package com.twu.biblioteca;

import java.io.IOException;

public class CheckInner implements LibraryAction {
    private IOManager ioManager;
    private Library library;

    private String ACTION_NAME = "Check In A Book";

    public CheckInner(Library library, IOManager ioManager) {
        this.library = library;
        this.ioManager = ioManager;
    }

    @Override
    public void performAction() throws IOException {
        String title = ioManager.promptUserInput("Enter a title:");
        LibraryBook book = library.findBook(title);

        if (book==null) {
            ioManager.print("Book title not found.");
        }
        else{
            boolean successfulCheckIn = book.tryCheckIn();
            if (successfulCheckIn){
                ioManager.print("Thank you for returning the book.");
            }
            else{
                ioManager.print("That is not a valid book to return.");
            }
        }
    }

    public String toString() {
        return ACTION_NAME;
    }
}
